package com.aiti.lulian.service.impl;

import cn.hutool.core.util.StrUtil;
import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.lulian.entity.LuLianAnnouncement;
import com.aiti.lulian.mapper.LuLianAnnouncementMapper;
import com.aiti.lulian.service.ILuLianAnnouncementService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author WongMz
 * @CreateDate 2024-08-19
 * @Description: 通知公告服务层实现类
 */
@Service
public class LuLianAnnouncementServiceImpl extends BaseSerivceImpl<LuLianAnnouncementMapper, LuLianAnnouncement> implements ILuLianAnnouncementService {

    @Autowired
    private LuLianAnnouncementMapper announcementMapper;

    @Override
    public Map<String, Object> queryList(Integer pageNum, Integer pageSize, LuLianAnnouncement announcement) {
        Map<String, Object> map = new HashMap<>();

        Page<LuLianAnnouncement> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<LuLianAnnouncement> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LuLianAnnouncement::getIsDel, announcement.getIsDel());
        if (StrUtil.isNotBlank(announcement.getType())) {
            wrapper.eq(LuLianAnnouncement::getType, announcement.getType());
        }
        wrapper.orderByDesc(LuLianAnnouncement::getBaseCreateTime);
        Page<LuLianAnnouncement> pageResult = announcementMapper.selectPage(page, wrapper);
        List<LuLianAnnouncement> records = pageResult.getRecords();

        map.put("total", pageResult.getTotal());
        map.put("list", records);

        return map;
    }
}